package com.dxy.authresource.core;

import org.springframework.boot.actuate.endpoint.RequestMappingEndpoint;
import org.springframework.context.ApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import java.util.Map;

/**
 * Created by cxf_dxy on 2018/10/25.
 */
public class RequestMappingPEndpoint extends RequestMappingEndpoint {

    @Override
    protected void extractMethodMappings(ApplicationContext applicationContext, Map<String, Object> result) {
        if (applicationContext != null) {
            for (Map.Entry<String, AbstractHandlerMethodMapping> bean : applicationContext
                    .getBeansOfType(AbstractHandlerMethodMapping.class).entrySet()) {
                @SuppressWarnings("unchecked")
                Map<?, HandlerMethod> methods = bean.getValue().getHandlerMethods();
                for (Map.Entry<?, HandlerMethod> method : methods.entrySet()) {
                    result.put(method.getKey().toString(), DataBuilder.build(method,bean));
                }
            }
        }
    }
}
